<script type="text/javascript">
$(function(){
	var pg = App.message.queueCount.ui, pp = pg.params || {},
		gd = pg.find('.grid');

	var frm = {
		title: pg.seek('title'),
		date: [ pg.seek('startDate'), pg.seek('endDate') ],
		hour: [ pg.seek('startH'), pg.seek('endH') ],
		minute: [ pg.seek('startM'), pg.seek('endM') ],
		second: [ pg.seek('startS'), pg.seek('endS') ]
	}
	frm.title.text(pp.code);
	
	gd.mac('grid', {
		key: 'id',
		cols: [{
			field: 'num', title : '消息状态', width: 150, 
			render: function(r){
				if (r.tStatus == 'all') {
					return '消息总数';
				}
				return Cache.message.status[r.tStatus];
			}
		}, {
			field: 'iAddTime', title : '消息数', width: 200,
			render: function(r){
				return r.count;
			}
		},],
 		loader: {
			url: App.ctx + '/broker/count.do',
			params: {
				pageNo: 1, pageSize: 20, target: pp.code
			},
			autoLoad: true
		}, 
	});

	var dateCfg = {
		prevText: "<上一月",
		nextText: "下一月>",
		dateFormat: "yy-mm-dd",
		changeMonth: true,
		changeYear: true,
		inline: true
	};
	frm.date[0].datepicker(dateCfg);
	frm.date[1].datepicker(dateCfg);

	function adjust(){
		var h = pg.height() - 132;
		gd.parent().height(h);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
	
	function getTime(i){
		var d = frm.date[i].val(), h = frm.hour[i].val() || 0,
			m = frm.minute[i].val() || 0, s = frm.second[i].val() || 0;
		if (!d) {
			return null;
		}
		h =  (h < 10? '0':'') + h;
		m =  (m < 10? '0':'') + m;
		s =  (s < 10? '0':'') + s;
		return d + ' ' + h + ':' + m + ':' + s;
	}
	
	function validate(){
		var s = frm.date[0].val(); 
		var e = frm.date[1].val();
		if (!s && !e) {
			return true;
		}
		return e > s;
	}
	pg.seek('ok').click(function(e) {
		if (!validate()) { 
			mac.alert('结束时间应大于开始时间');
		} else {
			gd.load({ startTime: getTime(0), endTime: getTime(1) });
		} 
	});
	pg.seek('close').click(function(){
		pg.close();
	});
});
</script>
<div class="top">
	<div class="item">
		<div class="label">时间范围：</div>
		<input class="long" name="startDate" />
		<span>&nbsp;</span>
		<input class="short" type="number" max="59" min="0" placeholder="时" name="startH"/>
		<span>:</span>
		<input class="short" type="number" max="59" min="0" placeholder="分" name="startM"/>
		<span>:</span>
		<input class="short" type="number" max="59" min="0" placeholder="秒" name="startS"/>
		<span>&nbsp;到&nbsp;</span>
		<input class="long" name="endDate" />
		<span>&nbsp;</span>
		<input class="short" type="number" max="59" min="0" placeholder="时" name="endH"/>
		<span>:</span>
		<input class="short" type="number" max="59" min="0" placeholder="分" name="endM"/>
		<span>:</span>
		<input class="short" type="number" max="59" min="0" placeholder="秒" name="endS"/>
		<button name="ok">统计</button>
		<div class="clear"></div>
	</div>
</div>
<div class="body">
	<div class="grid"></div>
</div>
<div class="foot">
	<button name="close">关闭</button>
</div>